import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { ObjCreate } from "../../common/ObjCreate";
import { GImageBitmap } from "../../../../../com/mui/controls/GImageBitmap";
import { ImagesConst } from "../../../resource/ImagesConst";
import { Language } from "../../../../../extend/language/Language";
import { SGangFightsTeamMember } from "../../../../../Message/Public/SGangFightsTeamMember";
import { ObjTeamCreate } from "../../common/ObjTeamCreate";
import { CareerConfig } from "../../../resource/CareerConfig";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { EGangFightsTeamPos } from "../../../../../Message/Public/EGangFightsTeamPos";
import { SLookupPlayerReply } from "../../../../../Message/Game/SLookupPlayerReply";
import { EntityUtil } from "../../../scene/layer/utils/EntityUtil";
import { StatueUserPlayer } from "../../../scene/player/entity/StatueUserPlayer";
import { UserEquipmentUtil } from "../../range/userEquip/UserEquipmentUtil";
import { DirectionType } from "../../../scene/modle/data/DirectionType";
import { Cache } from "../../../cache/Cache";
import { PlayerOpRegister } from "../../common/menu/PlayerOpRegister";
import { PlayerMiniInfo } from "../../../model/PlayerMiniInfo";
import { SEntityId } from "../../../../../Message/Public/SEntityId";
//class GangFightsMyTeamPlayerCell
    
    export  class GangFightsMyTeamPlayerCell /* flash.display.Sprite */
    {
        constructor()
        {
            
            this.init();
            return;
        }

        /* internal  */init(): void
        {
            var loc1=GlobalStyle.textFormat6;
            loc1.align = flash.text.TextFormatAlign.CENTER;
            this._tfPlayerName = ObjCreate.createTextField("", 0, 0, 196, 20, this, loc1);
            this._bmpCaptain = new GImageBitmap(ImagesConst.GangFightsRoleBg, 0, 18);
            this.addChild(this._bmpCaptain);
            this._bmpTeamLeader = new GImageBitmap("TeamLeader.png", 0, 18);
            this._tfNotOnline = ObjCreate.createTextField(Language.getString(44431), 55, 94, 150, 20, this, GlobalStyle.textFormat2);
            this._tfScore = ObjCreate.createTextField(Language.getString(44432), 44, 254, 130, 20, this);
            this._tfWerfare = ObjCreate.createTextField(Language.getString(44433), 44, 272, 130, 20, this);
            this._tfLevel = ObjCreate.createTextField(Language.getString(44434), 44, 290, 130, 20, this);
            this._tfCareer = ObjCreate.createTextField(Language.getString(44435), 44, 308, 130, 20, this);
            return;
        }

        public updateMember(arg1: SGangFightsTeamMember): void
        {
            this._player = arg1;
            if (arg1) 
            {
                this._tfPlayerName.htmlText = arg1.name;
                ObjTeamCreate.setTextFieldKeyValue(this._tfScore, Language.getString(44432), arg1.mark.toString());
                ObjTeamCreate.setTextFieldKeyValue(this._tfWerfare, Language.getString(44433), arg1.warfare.toString());
                ObjTeamCreate.setTextFieldKeyValue(this._tfLevel, Language.getString(44434), arg1.level.toString());
                ObjTeamCreate.setTextFieldKeyValue(this._tfCareer, Language.getString(44435), CareerConfig.instance.getInfoByCode(arg1.career).name);
                this.visible = true;
                Dispatcher.dispatchEvent(new DataEvent(EventName.GangfightsGetPlayerMsg, this._player.entityId));
                if (arg1.pos.value() != EGangFightsTeamPos._EGangFightsTeamLeader) 
                {
                    if (this._bmpTeamLeader && this._bmpTeamLeader.parent) 
                    {
                        this._bmpTeamLeader.parent.removeChild(this._bmpTeamLeader);
                    }
                }
                else 
                {
                    this._bmpTeamLeader = new GImageBitmap("TeamLeader.png", 0, 18);
                    this.addChild(this._bmpTeamLeader);
                }
            }
            else 
            {
                this._tfPlayerName.text = "";
                this._tfScore.text = Language.getString(44432);
                this._tfWerfare.text = Language.getString(44433);
                this._tfLevel.text = Language.getString(44434);
                this._tfCareer.text = Language.getString(44435);
                this.visible = false;
            }
            return;
        }

        public updatePlayerInfo(arg1: SLookupPlayerReply): void
        {
            var loc1=null;
            var loc2=null;
            if (this._player && EntityUtil.equal(arg1.miniPlayer.entityId, this._player.entityId)) 
            {
                if (this._playerModel) 
                {
                    this._playerModel.dispose(false);
                }
                else 
                {
                    this._playerModel = new StatueUserPlayer();
                }
                loc1 = UserEquipmentUtil.getEquipmentData(arg1.playerItemUpdates);
                loc2 = UserEquipmentUtil.getUserEquipmentData(loc1, arg1.fashionState, arg1.wingState, arg1.fashionWeaponState, arg1.surroundState, arg1.waistBeltState, arg1.elfState);
                this._playerModel.direction = DirectionType.South;
                this._playerModel.camp = arg1.miniPlayer.camp;
                this._playerModel.sex = arg1.miniPlayer.sex;
                this._playerModel.career = arg1.miniPlayer.career;
                this._playerModel.reserveJs.weaponStPerLv = loc2.weaponStPerLv;
                this._playerModel.reserveJs.wingStrPerLv = loc2.wingStLv;
                this._playerModel.updateEquipByDic(loc2.equipDic);
                this._playerModel.x = 95;
                this._playerModel.y = 209;
                addChildAt(this._playerModel, 3);
                this._tfNotOnline.visible = false;
                if (arg1.miniPlayer.online && !EntityUtil.equal(arg1.miniPlayer.entityId, Cache.instance.role.entityInfo.entityId)) 
                {
                    this._tfPlayerName.htmlText = "<font color=\'#00FF00\'><u>" + arg1.miniPlayer.name + "</u></font>";
                    PlayerOpRegister.Register(this._tfPlayerName, new PlayerMiniInfo(arg1.miniPlayer));
                }
                else if (!arg1.miniPlayer.online) 
                {
                    this._tfPlayerName.htmlText = arg1.miniPlayer.name;
                    this._tfPlayerName.textColor = 10461087;
                    PlayerOpRegister.UnRegister(this._tfPlayerName);
                }
            }
            return;
        }

        public updatePlayerNotOnline(arg1: SEntityId): void
        {
            if (this._player && EntityUtil.equal(arg1, this._player.entityId)) 
            {
                if (this._playerModel) 
                {
                    this._playerModel.dispose(false);
                }
                this._tfNotOnline.visible = true;
            }
            return;
        }

        /* internal */ /* var */_tfPlayerName: Object /* flash.text.TextField */;

        /* internal */ /* var */_bmpCaptain: GImageBitmap;

        /* internal */ /* var */_tfScore: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfWerfare: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfLevel: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfCareer: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfNotOnline: Object /* flash.text.TextField */;

        /* internal */ /* var */_playerModel: StatueUserPlayer;

        /* internal */ /* var */_bmpTeamLeader: GImageBitmap;

        /* internal */ /* var */_player: SGangFightsTeamMember;
    }
